package com.forestar.xzk.permission;

import android.Manifest;
import android.content.pm.PackageManager;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;

import java.util.Arrays;

/**
 * created by  xzk
 * 2020/7/17   10:14
 * 说明:  权限申请外部类，用于申请敏感权限的
 */
public class PermissionHelper {

//    final String[] LOCATIONGPS = new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
//            Manifest.permission.ACCESS_FINE_LOCATION,
//            Manifest.permission.READ_PHONE_STATE};
//    /**
//     * 检查出发现授权失败的就返回并进行授权
//     * @return
//     */
//    private String checkPermissionForRequest() {
//        for (int i = 0; i < LOCATIONGPS.length; i++) {
//            Log.d(TAG, "授权:" + LOCATIONGPS[i] + "---" + ActivityCompat.checkSelfPermission(this, LOCATIONGPS[i]));
//            if (ActivityCompat.checkSelfPermission(this, LOCATIONGPS[i]) != PackageManager.PERMISSION_GRANTED) {
//                return LOCATIONGPS[i];
//            }
//        }
//        return null;
//    }
//
//    public final int requestTag = 1002;
//
//    @Override
//    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//        Log.d(TAG,"获取权限结果"+ Arrays.toString(permissions) + " Granted");
//        if(requestCode==requestTag){
//            String forRequest = checkPermissionForRequest();
//            if(null != forRequest){
//                //权限失败  申请权限
//                ActivityCompat .requestPermissions(this, LOCATIONGPS , requestTag);
//            }else{
//                getLocation();
//            }
//        }
//    }


}
